package com.zyuan.lawyerport.view.cModule;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.zyuan.lawyerport.R;
import com.zyuan.lawyerport.view.cModule.activity.CompleteOrderDetailsActivity;
import com.zyuan.lawyerport.view.cModule.activity.HasEvaluationOrderActivity;
import com.zyuan.lawyerport.view.cModule.activity.OngoingOrderDetailsActivity;
import com.zyuan.lawyerport.view.cModule.adapter.OrderAdapter;
import com.zyuan.lawyerport.view.cModule.bean.OrderBean;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import common.base.fragment.BaseFragment;

/**
 * description 模块3
 * Created by JustTong on 2018/11/28.
 */
public class ModuleCFragment extends BaseFragment {

    @BindView(R.id.rv_main)
    RecyclerView rvMain;
    @BindView(R.id.srl_main)
    SwipeRefreshLayout srlMain;

    OrderAdapter adapter;

    @Override
    public void init() {
        List<OrderBean> list = new ArrayList<>();
        Random ra = new Random();
        for (int i = 0; i < 10; i++) {

            list.add(new OrderBean(i, "a" + i, ra.nextInt(3)));

        }
        adapter = new OrderAdapter(list);

        rvMain.setLayoutManager(new LinearLayoutManager(activity));
        rvMain.setAdapter(adapter);

        adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                if (ModuleCFragment.this.adapter.getData().get(position).getType() == 0) {
                    startActivity(new Intent(activity, OngoingOrderDetailsActivity.class));
                } if (ModuleCFragment.this.adapter.getData().get(position).getType() == 1) {
                    startActivity(new Intent(activity, CompleteOrderDetailsActivity.class));
                } if (ModuleCFragment.this.adapter.getData().get(position).getType() == 2) {
                    startActivity(new Intent(activity, HasEvaluationOrderActivity.class));
                }
            }
        });
    }

    @Override
    public int setLayout() {
        return R.layout.fragment_order_layout;
    }

    @Override
    public void initLoadStart() {

    }

    @Override
    public void initLoadEnd() {

    }

    @Override
    public void initBindingView(Object mBean) {
        if (srlMain != null) {
            srlMain.setRefreshing(false);
        }

    }

}
